<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <title>客户列表</title>
    
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->

  </head>
  
  <body>
<h3 align="center">客户列表</h3>
<table border="1" width="70%" align="center">
	<tr>
		<th>客户姓名</th>
		<th>性别</th>
		<th>生日</th>
		<th>手机</th>
		<th>邮箱</th>
		<th>描述</th>
		<th>操作</th>
	</tr>
	<c:forEach items="${requestScope.pageBean.datas}" var="cstm">
		<tr>
			<td>${cstm.cname }</td>
			<td>${cstm.gender }</td>
			<td>${cstm.birthday }</td>
			<td>${cstm.cellphone }</td>
			<td>${cstm.email }</td>
			<td>${cstm.description }</td>
			<td>
				<a href="<c:url value='/CustomerServlet?method=preEdit&cid=${cstm.cid}'/>">编辑</a>
				<a href="<c:url value='/CustomerServlet?method=delete&cid=${cstm.cid}'/>">删除</a>
			</td>
		</tr>
	</c:forEach>
	<%-- 	<tr>
			<td>张三</td>
			<td>男</td>
			<td>2013-05-05</td>
			<td>13899996666</td>
			<td>zhangSan@163.com</td>
			<td>张三是谁？</td>
			<td>
				<a href="<c:url value='/edit.jsp'/>">编辑</a>
				<a href="<c:url value='/msg.jsp'/>">删除</a>
			</td>
		</tr> --%>
</table>
	<center>
		第${pageBean.currPageCode }页/共${pageBean.totalPage }页
		<a href="${pageBean.url}&currPageCode=1">首页</a>
		<c:if test="${pageBean.currPageCode > 1}">
			<a href="${pageBean.url}&currPageCode=${pageBean.currPageCode-1}">上一页</a>
		</c:if>
		<%-- 计算begin、end --%>
		<c:choose>
			<%-- 当总页数不足10页时，全部显示  --%>
			<c:when test="${pageBean.totalPage <= 10}">
				<c:set var="begin" value="1"/>
				<c:set var="end" value="${pageBean.totalPage}" />
			</c:when>
			<c:otherwise>
				<%-- 当总页数 > 10时，通过公式计算出begin、end --%>
				<c:set var="begin" value="${pageBean.currPageCode - 5}"/>
				<c:set var="end" value="${pageBean.currPageCode + 4}"/>
				<%-- 头溢出 --%>
				<c:if test="${begin < 1}">
					<c:set var="begin" value="1"/>
					<c:set var="end" value="10"/>
				</c:if>
				<%-- 尾溢出 --%>
				<c:if test="${end > pageBean.totalPage}">
					<c:set var="begin" value="${pageBean.totalPage - 9}"/>
					<c:set var="end" value="${pageBean.totalPage}"/>
				</c:if>
				
			</c:otherwise>	
		</c:choose>
		<c:forEach var="i" begin="${begin}" end="${end}">
			<c:choose>
				<c:when test="${pageBean.currPageCode == i}">
					&nbsp;${i}&nbsp;
				</c:when>
				<c:otherwise>
					&nbsp;<a href="${pageBean.url}&currPageCode=${i}">${i}</a>&nbsp;
				</c:otherwise>
			</c:choose>
		</c:forEach>
		
		<c:if test="${pageBean.currPageCode < pageBean.totalPage}">
			<a href="${pageBean.url}&currPageCode=${pageBean.currPageCode+1}">下一页</a>
		</c:if>
		<a href="${pageBean.url}&currPageCode=${pageBean.totalPage}">尾页</a>
	</center>

  </body>
</html>
